package com.homedo.microservice.open.service.gateway.manager.web.turbine;

import org.springframework.cloud.client.ServiceInstance;

import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;


public class LocalServiceInstance implements ServiceInstance {

    private URI uri;
    private String host;
    private int port;
    private boolean secure;
    private Map<String, String> metadata = new LinkedHashMap<>();
    private String serviceId;

    public LocalServiceInstance() {
    }

    public LocalServiceInstance(URI uri) {
        setUri(uri);
    }

    public void setUri(URI uri) {
        this.uri = uri;
        this.host = this.uri.getHost();
        this.port = this.uri.getPort();
        String scheme = this.uri.getScheme();
        if ("https".equals(scheme)) {
            this.secure = true;
        }
    }

    @Override
    public String getServiceId() {
        return this.serviceId;
    }

    public void setServiceId(String id) {
        this.serviceId = id;
    }

    @Override
    public String getHost() {
        return this.host;
    }

    @Override
    public int getPort() {
        return this.port;
    }

    @Override
    public boolean isSecure() {
        return this.secure;
    }

    @Override
    public URI getUri() {
        return this.uri;
    }

    @Override
    public Map<String, String> getMetadata() {
        return this.metadata;
    }
}
